﻿#include<cstring>
#include<time.h>
#include "AutoHeader.h"
#include<stdlib.h>

typedef hyperlex::tree<hyperlex::GrammarTree::TreeInfor> GTNode;
typedef hyperlex::tree<hyperlex::GrammarTree::TreeInfor>::PostIterator GTiterator;

int static Test000(const hyperlex::dictionary& para);
int static Test001(const hyperlex::dictionary& para);
int static Test002(const hyperlex::dictionary& para);
int static Test003(const hyperlex::dictionary& para);
int static Test004(const hyperlex::dictionary& para);
int static Test005(const hyperlex::dictionary& para);
int static Test006(const hyperlex::dictionary& para);
int static Test007(const hyperlex::dictionary& para);
int static Test008(const hyperlex::dictionary& para);
int static Test009(const hyperlex::dictionary& para);
int static Test010(const hyperlex::dictionary& para);
int static Test011(const hyperlex::dictionary& para);
int static Test012(const hyperlex::dictionary& para);
int static Test013(const hyperlex::dictionary& para);
int static Test014(const hyperlex::dictionary& para);
int static Test015(const hyperlex::dictionary& para);
int static Test016(const hyperlex::dictionary& para);
int static Test017(const hyperlex::dictionary& para);
int static Test018(const hyperlex::dictionary& para);
int static Test019(const hyperlex::dictionary& para);
int static Test020(const hyperlex::dictionary& para);
int static Test021(const hyperlex::dictionary& para);
int static Test022(const hyperlex::dictionary& para);
int static Test023(const hyperlex::dictionary& para);
int static Test024(const hyperlex::dictionary& para);
int static Test025(const hyperlex::dictionary& para);
int static Test026(const hyperlex::dictionary& para);
int static Test027(const hyperlex::dictionary& para);
int static Test028(const hyperlex::dictionary& para);
int static Test029(const hyperlex::dictionary& para);
int static Test030(const hyperlex::dictionary& para);
int static Test031(const hyperlex::dictionary& para);
int static Test032(const hyperlex::dictionary& para);
int static Test033(const hyperlex::dictionary& para);
int static Test034(const hyperlex::dictionary& para);
int static Test035(const hyperlex::dictionary& para);
int static Test036(const hyperlex::dictionary& para);
int static Test037(const hyperlex::dictionary& para);
int static Test038(const hyperlex::dictionary& para);
int static Test039(const hyperlex::dictionary& para);
int static Test040(const hyperlex::dictionary& para);
int static Test041(const hyperlex::dictionary& para);
int static Test042(const hyperlex::dictionary& para);
int static Test043(const hyperlex::dictionary& para);
int static Test044(const hyperlex::dictionary& para);
int static Test045(const hyperlex::dictionary& para);
int static Test046(const hyperlex::dictionary& para);
int static Test047(const hyperlex::dictionary& para);
int static Test048(const hyperlex::dictionary& para);
int static Test049(const hyperlex::dictionary& para);
int static Test050(const hyperlex::dictionary& para);
int static Test051(const hyperlex::dictionary& para);
int static Test052(const hyperlex::dictionary& para);
int static Test053(const hyperlex::dictionary& para);
int static Test054(const hyperlex::dictionary& para);
int static Test055(const hyperlex::dictionary& para);
int static Test056(const hyperlex::dictionary& para);
int static Test057(const hyperlex::dictionary& para);
int static Test058(const hyperlex::dictionary& para);
int static Test059(const hyperlex::dictionary& para);
int static Test060(const hyperlex::dictionary& para);
int static Test061(const hyperlex::dictionary& para);
int static Test062(const hyperlex::dictionary& para);
int static Test063(const hyperlex::dictionary& para);
static char* CopyMalloc(const char* s);
static void CopyNc(const char* src, char* dst, size_t length);
static size_t strlength(const char* str);
static bool compare(const char* str1, const char* str2);
int testNew(hyperlex::dictionary& para)
{
	int item = para.search(1L, "TestItem::item");
	int error = 0;
	std::cout << "item: " << item << std::endl;
	switch (item)
	{
	case 0:
	{
		error = Test000(para);
		break;
	}
	case 1:
	{
		error = Test001(para);
		break;
	}
	case 2:
	{
		std::cout << "Test class file path "<< std::endl;
		error = Test002(para);
		break;
	}
	case 3:
	{
		error = Test003(para);
		break;
	}
	case 4:
	{
		error = Test004(para);
		break;
	}
	case 5:
	{
		std::cout << "Test dequeheader " << std::endl;
		error = Test005(para);
		break;
	}
	case 6:
	{
		error = Test006(para);
		break;
	}
	case 7:
	{
		error = Test007(para);
		break;
	}
	case 8:
	{
		error = Test008(para);
		break;
	}
	case 9:
	{
		error = Test009(para);
		break;
	}
	case 10:
	{
		error = Test010(para);
		break;
	}
	case 11:
	{
		error = Test011(para);
		break;
	}
	case 12:
	{
		error = Test012(para);
		break;
	}
	case 13:
	{
		error = Test013(para);
		break;
	}
	case 14:
	{
		error = Test014(para);
		break;
	}
	case 15:
	{
		error = Test015(para);
		break;
	}
	case 16:
	{
		error = Test016(para);
		break;
	}
	case 17:
	{
		error = Test017(para);
		break;
	}
	case 18:
	{
		error = Test018(para);
		break;
	}
	case 19:
	{
		error = Test019(para);
		break;
	}
	case 20:
	{
		error = Test020(para);
		break;
	}
	case 21:
	{
		error = Test021(para);
		break;
	}
	case 22:
	{
		error = Test022(para);
		break;
	}
	case 23:
	{
		error = Test023(para);
		break;
	}
	case 24:
	{
		error = Test024(para);
		break;
	}
	case 25:
	{
		error = Test025(para);
		break;
	}
	case 26:
	{
		error = Test026(para);
		break;
	}
	case 27:
	{
		error = Test027(para);
		break;
	}
	case 28:
	{
		error = Test028(para);
		break;
	}
	case 29:
	{
		error = Test029(para);
		break;
	}
	case 30:
	{
		error = Test030(para);
		break;
	}
	case 31:
	{
		error = Test031(para);
		break;
	}
	case 32:
	{
		error = Test032(para);
		break;
	}
	case 33:
	{
		error = Test033(para);
		break;
	}
	case 34:
	{
		error = Test034(para);
		break;
	}
	case 35:
	{
		error = Test035(para);
		break;
	}
	case 36:
	{
		error = Test036(para);
		break;
	}
	case 37:
	{
		error = Test037(para);
		break;
	}
	case 38:
	{
		error = Test038(para);
		break;
	}
	case 39:
	{
		error = Test039(para);
		break;
	}
	case 40:
	{
		error = Test040(para);
		break;
	}
	case 41:
	{
		error = Test041(para);
		break;
	}
	case 42:
	{
		error = Test042(para);
		break;
	}
	case 43:
	{
		error = Test043(para);
		break;
	}
	case 44:
	{
		error = Test044(para);
		break;
	}
	case 45:
	{
		error = Test045(para);
		break;
	}
	case 46:
	{
		error = Test046(para);
		break;
	}
	case 47:
	{
		error = Test047(para);
		break;
	}
	case 48:
	{
		error = Test048(para);
		break;
	}
	case 49:
	{
		error = Test049(para);
		break;
	}
	case 50:
	{
		error = Test050(para);
		break;
	}
	case 51:
	{
		error = Test051(para);
		break;
	}
	case 52:
	{
		error = Test052(para);
		break;
	}
	case 53:
	{
		error = Test053(para);
		break;
	}
	case 54:
	{
		error = Test054(para);
		break;
	}
	case 55:
	{
		error = Test055(para);
		break;
	}
	case 56:
	{
		error = Test056(para);
		break;
	}
	case 57:
	{
		error = Test057(para);
		break;
	}
	case 58:
	{
		error = Test058(para);
		break;
	}
	case 59:
	{
		error = Test059(para);
		break;
	}
	case 60:
	{
		error = Test060(para);
		break;
	}
	case 61:
	{
		error = Test061(para);
		break;
	}
	case 62:
	{
		error = Test062(para);
		break;
	}
	case 63:
	{
		error = Test063(para);
		break;
	}

	default:
	{
		error = Test000(para);
		break;
	}
		
	}
	return error;
}
class CFile
{
public:
	CFile();
	~CFile();
	FILE* Open(const char* name, const char* mode);
	FILE* OpenRead(const char* s);//SH_read_from_file__(const char* s);
	FILE* OpenWriteAtRear(const char* s);//fp_write_at_rear(const char* s);
	FILE* OpenWritePlus(const char* s);//fp_write_plus
	std::string FusePathAndName(const std::string& path, const std::string& name);//path_add_file_name
	std::string FusePathAndName(const char* path, const std::string& name);//path_add_file_name
	std::string ChangeSuffix(const std::string& file, const char* new_one);//string suffix_change(const string& file, const char* new_one);
private:

};

struct PreTreat
{
	enum regular
	{
		_identifier_ = 1,
		_integer_ = 2,
		_CommonChar_ = 3,
		_idChar_ = 4,
		_string_ = 5,
		_include_ = 6,
		_spaces_ = 7,
		_enters_ = 8,
		_tab_ = 9,
		_semicolon_ = 10,
		_colon_ = 11,
		_dot_ = 12,
		_braceL_ = 13,
		_braceR_ = 14,
		_left_ = 15,
		_right_ = 16,
		_squareL_ = 17,
		_squareR_ = 18,
		_angleL_ = 19,
		_angleR_ = 20,
		_anntationS_ = 21,
		_anntationM_ = 22,
		_range_ = 23,
		_star_ = 24,
		_plus_ = 25,
		_question_ = 26,
		_or_ = 27
	};
	enum group
	{
		_identifier___ = 1,
		_const___ = 2,
		_string___ = 3,
		_include___ = 4,
		_format___ = 5,
		_division___ = 6,
		_braket___ = 7,
		_anntation___ = 8,
		_RegSymbol___ = 9
	};
	static int next(int state, const char c);
	static int action(int state);
	static int GroupGet(int state);
};
int static Test000(const hyperlex::dictionary& para)
{
	hyperlex::InputPanel IP;
	std::string file;
	FILE* fp;
	hyperlex::BufferChar input;
	hyperlex::BufferChar temp;
	CFile CF;
	std::string OutputLabel2, OutputLabel;
	OutputLabel = para.search("lexer", "OutputLabel");
	OutputLabel2 = para.search("parser", "OutputLabel2");
	int error = 0;
	file = para.search("./data/grammerT.txt", "InputFileName");
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fp = CF.OpenRead(file.c_str());
	std::cout << "InputFileName: " << file << std::endl;
	input << fp;
	temp.append(input);
	std::cout << "/*" << std::endl;
	std::cout << temp.ptr() << std::endl;
	std::cout << "*/" << std::endl;
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fclose(fp);

	hyperlex::Morpheme here;
	here.Build<PreTreat>(input.ptr());
	
	here.Demo(stdout);

	hyperlex::Morpheme derived;

	derived.Build<PreTreat>(here);

	derived.Demo(stdout);

	std::cout << "derived == here : " << (derived == here) << std::endl;

	here.insert(0, 286, derived);
	std::cout << "derived == here : " << (derived == here) << std::endl;

	hyperlex::Morpheme newOne;
	//newOne.Demo(stdout);
	newOne.insert(4, 286, derived);
	//newOne.Demo(stdout);
	std::cout << "newOne == derived : " << (newOne == derived) << std::endl;

	return error;
}

struct Preparser
{
	enum type
	{
		accept = 0,
		error = 1,
		push = 2,
		reduce = 3
	};
	enum rules
	{
		all_all_ = 0,
		TEXT_meow_ = 1,
		//<DEF*>_first_ = 2,
		//<DEF*>_multi_ = 3,
		DEF_anntation_ = 4,
		DEF_anything_ = 5,
		DEF_include_ = 6,
		//[anntation]_anntationS_ = 7,
		//[anntation]_anntationM_ = 8,
		INCLUDE_include_ = 9,
		INCLUDE_include2_ = 10,
		ANY_identifier_ = 11,
		ANY_const_ = 12,
		ANY_RegSymbol_ = 13,
		ANY_braket_ = 14,
		ANY_division_ = 15,
		ANY_format_ = 16,
		//[identifier]_identifier_ = 17,
		//[const]_integer_ = 18,
		//[const]_CommonChar_ = 19,
		//[const]_idChar_ = 20,
		//[RegSymbol]_range_ = 21,
		//[RegSymbol]_star_ = 22,
		//[RegSymbol]_plus_ = 23,
		//[RegSymbol]_question_ = 24,
		//[RegSymbol]_or_ = 25,
		//[braket]_braceL_ = 26,
		//[braket]_braceR_ = 27,
		//[braket]_left_ = 28,
		//[braket]_right_ = 29,
		//[braket]_squareL_ = 30,
		//[braket]_squareR_ = 31,
		//[braket]_angleL_ = 32,
		//[braket]_angleR_ = 33,
		//[division]_semicolon_ = 34,
		//[division]_colon_ = 35,
		//[division]_dot_ = 36,
		//[format]_spaces_ = 37,
		//[format]_enters_ = 38,
		//[format]_tab_ = 39
	};
	enum nonterminal
	{
		_all_ = 0,
		_TEXT_ = 1,
		//_<DEF*>_ = 2,
		_DEF_ = 3,
		//_[anntation]_ = 4,
		_INCLUDE_ = 5,
		_ANY_ = 6,
		//_[identifier]_ = 7,
		//_[const]_ = 8,
		//_[RegSymbol]_ = 9,
		//_[braket]_ = 10,
		//_[division]_ = 11,
		//_[format]_ = 12
	};
	static const size_t StateCount;
	static const size_t NonTerminalCount;
	static const size_t TerminalCount;
	static const size_t RulesCount;
	static const int GOTO[42][13];
	static const int ACTION[42][28];
	static const int RulesToSymbol[40];
	static const int RulesLength[40];
	static const char* const RulesName[40];
	static const int Implicit[40];
};

int static pretreatment(const char*SrcName, hyperlex::Morpheme& input, hyperlex::Morpheme& output)
{
	int error = output.Build<PreTreat>(input);
	output.append(SrcName);
	if (error != 0) return error * 16;
	bool include;
	do
	{
		include = false;
		size_t begin = 0;
		size_t count = 0;
		size_t file = 0;
		const char* name = NULL;
		hyperlex::GrammarTree Tree;
		error = Tree.build<Preparser>(output);
		if (error != 0) return error * 16 + 2;
		GTiterator iterator;
		iterator.initial(Tree.GT);
		while (iterator.still())
		{
			GTNode* GT = iterator.target();
			if (iterator.state() == 0)
			{
				size_t infor = GT->root().site;
				//std::cout << "infor: " << infor << std::endl;
				if (GT->root().rules)
				{
					if (infor == (int)Preparser::INCLUDE_include2_)
					{
						size_t site = GT->child(1)->root().site;
						include = true;
						begin = GT->child(0)->root().site;
						count = 2;
						//std::cout << "begin: " << begin << std::endl;
						//std::cout << "output.GetWord(site): " << output.GetWord(site) << std::endl;
						name = output.GetString(site);
						//std::cout << "name: " << name << std::endl;
						file = output[site].file;
						break;
					}
					else if(infor == (int)Preparser::INCLUDE_include_)
					{
						size_t site = GT->child(2)->root().site;
						include = true;
						begin = GT->child(0)->root().site;
						count = 3;
						//std::cout << "2begin: " << begin << std::endl;
						name = output.GetString(site);
						//std::cout << "2name: " << name << std::endl;
						file = output[site].file;
						break;
					}
				}
			}
			iterator.next();
		}
		if (include)
		{
			hyperlex::Morpheme eme;
			CFile CF;
			FILE* fp = CF.OpenRead(name);
			output.append(name);
			//output.Demo(stdout);
			int error = eme.Build<PreTreat>(fp);
			fclose(fp);
			if (error != 0) return error * 16 + 1;
			eme.SetFile(output.FileCount() - 1);
			output.insert(begin, count, eme);
			//output.Demo(stdout);
			
		}
	} while (include);
	
	return error;
}








int static Test001(const hyperlex::dictionary& para)
{
	int error = 0;
	hyperlex::InputPanel IP;
	std::string file;
	FILE* fp;
	hyperlex::BufferChar input;
	hyperlex::BufferChar temp;
	CFile CF;
	std::string OutputLabel2, OutputLabel;
	OutputLabel = para.search("lexer", "OutputLabel");
	OutputLabel2 = para.search("parser", "OutputLabel2");

	file = para.search("./data/grammerT.txt", "InputFileName");
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fp = CF.OpenRead(file.c_str());
	std::cout << "InputFileName: " << file << std::endl;
	input << fp;
	temp.append(input);
	std::cout << "/*" << std::endl;
	std::cout << temp.ptr() << std::endl;
	std::cout << "*/" << std::endl;
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fclose(fp);

	hyperlex::Morpheme here;
	error = here.Build<PreTreat>(input.ptr());
	std::cout << "error: " << error << std::endl;
	here.Demo(stdout);

	hyperlex::Morpheme derived;



	error = pretreatment(file.c_str(), here, derived);
	std::cout << "error: " << error << std::endl;
	derived.Demo(stdout);
	hyperlex::BufferChar MorOut;
	derived.print(MorOut);

	std::cout << MorOut.ptr() << std::endl;

	std::cout << "derived == here : " << (derived == here) << std::endl;
	
	return error;
}
struct test003
{
	static int infor;
	test003()
	{
		std::cout << "test003()" << std::endl;
		std::cout << "infor: " << infor << std::endl;
		infor += 1;
	}
	~test003()
	{
		std::cout << "~test003()" << std::endl;
		std::cout << "infor: " << infor << std::endl;
	}
};
int test003::infor = 0;
int static Test002(const hyperlex::dictionary& para)
{
	int error = 0;
	for (size_t i = 0; i < 16; i++)
	{
		test003 temp;
	}
	hyperlex::FilePath A, B, C;
	A.build(".//data///vain.txt");
	A.demo();
	B.build("header.h");
	B.demo();
	A += B;
	A.demo();
	B.build("/share/Hyper//./git/./././///../git/data/header.h");
	B.demo();
	B.clean();
	B.demo();
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	A += B;

	A.demo();
	A += B;
	A.demo();
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	A.build(".//data/././vain.txt");
	A.demo();
	C.demo();
	C += A;
	C.demo();
	A.copy(B);
	A.demo();
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	A.build("././././../hahahahahahahahaha/hahaha/header.txt");
	A.demo();
	B.copy(A);
	B.demo();
	A.RearCutAppend(B);
	A.demo();
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	A.build("././././../hahahahahahahahaha///gg/../hahaha/header.txt");
	A.demo();
	B.copy(A);
	B.demo();
	A.RearCutAppend(B);
	A.demo();
	A.RearCutAppend(B);
	A.demo();
	return error;
}
int static pretreatment(const char* SrcName, hyperlex::Morpheme& output)
{
	CFile CF;
	FILE* fp = fopen(SrcName, "r");
	int error = output.Build<PreTreat>(fp);
	output.append(SrcName);
	if (error != 0) return error * 16;
	bool include;
	do
	{
		include = false;
		size_t begin = 0;
		size_t count = 0;
		size_t file = 0;
		const char* name = NULL;
		hyperlex::GrammarTree Tree;
		error = Tree.build<Preparser>(output);
		if (error != 0) return error * 16 + 2;
		GTiterator iterator;
		iterator.initial(Tree.GT);
		while (iterator.still())
		{
			GTNode* GT = iterator.target();
			if (iterator.state() == 0)
			{
				size_t infor = GT->root().site;
				//std::cout << "infor: " << infor << std::endl;
				if (GT->root().rules)
				{
					if (infor == (int)Preparser::INCLUDE_include2_)
					{
						size_t site = GT->child(1)->root().site;
						include = true;
						begin = GT->child(0)->root().site;
						count = 2;
						name = output.GetString(site);
						file = output[site].file;
						break;
					}
					else if (infor == (int)Preparser::INCLUDE_include_)
					{
						size_t site = GT->child(2)->root().site;
						include = true;
						begin = GT->child(0)->root().site;
						count = 3;
						//std::cout << "2begin: " << begin << std::endl;
						name = output.GetString(site);
						//std::cout << "2name: " << name << std::endl;
						file = output[site].file;
						break;
					}
				}
			}
			iterator.next();
		}
		if (include)
		{
			hyperlex::Morpheme eme;
			hyperlex::FilePath left, here;
			here.build(name);
			//std::cout << "file: " << file << std::endl;
			//std::cout << "output.GetFile(file): " << output.GetFile(file) << std::endl;
			left.build(output.GetFile(file));
			//here.demo();
			//left.demo();
			left.RearCutAppend(here);

			//left.demo();
			//std::cout << "=============" << std::endl;
			char* newFile = left.print();
			FILE* fp2 = fopen(newFile, "r");
			output.append(newFile);
			free(newFile);

			int error = eme.Build<PreTreat>(fp2);
			fclose(fp2);
			if (error != 0) return error * 16 + 1;
			eme.SetFile(output.FileCount() - 1);

			for (size_t i = 0; i + 1 < output.FileCount(); i++)
			{
				hyperlex::FilePath right;
				right.build(output.GetFile(i));
				if (left == right) return error * 16 + 5;
			}
		   
			output.insert(begin, count, eme);

		}
	} while (include);

	return error;
}
int static Test003(const hyperlex::dictionary& para)
{
	int error = 0;
	hyperlex::InputPanel IP;
	std::string file;
	FILE* fp;
	hyperlex::BufferChar input;
	hyperlex::BufferChar temp;
	CFile CF;
	std::string OutputLabel2, OutputLabel;
	OutputLabel = para.search("lexer", "OutputLabel");
	OutputLabel2 = para.search("parser", "OutputLabel2");

	file = para.search("./data/grammerT.txt", "InputFileName");
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fp = CF.OpenRead(file.c_str());
	std::cout << "InputFileName: " << file << std::endl;
	input << fp;
	temp.append(input);
	std::cout << "/*" << std::endl;
	std::cout << temp.ptr() << std::endl;
	std::cout << "*/" << std::endl;
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	fclose(fp);

	hyperlex::Morpheme here;
	error = here.Build<PreTreat>(input.ptr());
	std::cout << "error: " << error << std::endl;
	here.Demo(stdout);

	hyperlex::Morpheme derived;

	error = pretreatment(file.c_str(), derived);

	std::cout << " error = pretreatment(file.c_str(), derived);: " << error << std::endl;
	derived.Demo(stdout);
	hyperlex::BufferChar MorOut;
	derived.print(MorOut);

	std::cout << MorOut.ptr() << std::endl;

	std::cout << "derived == here : " << (derived == here) << std::endl;

	return error;
}
int static Test004(const hyperlex::dictionary& para)
{
	int error = 0;
	para.print(stdout);
	hyperlex::dictionary temp;
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	temp.copy(para);
	temp.print(stdout);
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;

	hyperlex::FilePath Opath;
	hyperlex::FilePath O_1, O_2, O_3;
	Opath.build("./data/output/fun");

	O_1.build(temp.search("L.txt", "OutputFileName"));
	O_2.build(temp.search("G.txt", "OutputFileName2"));
	O_3.build(temp.search("G2.txt", "OutputFileName3"));

	hyperlex::FilePath F_1, F_2, F_3;

	F_1.copy(Opath);
	F_2.copy(Opath);
	F_3.copy(Opath);
	
	F_1.demo();

	F_1.RearOnlyAppend(O_1);
	F_2.RearOnlyAppend(O_2);
	F_3.RearOnlyAppend(O_3);

	F_1.demo();
	F_2.demo();
	F_3.demo();

	temp.assign("OutputFileName", F_1.path());
	temp.assign("OutputFileName2", F_2.path());
	temp.assign("OutputFileName3", F_3.path());
	
	temp.assign("OutputFileName1", "test");
	std::cout << "+++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
	temp.print(stdout);
	return error;
}

static char* string_from_header(const char* header)
{
	if (header == NULL) return NULL;

	// 处理空字符串的情况
	if (*header == '\0') return CopyMalloc("\"\"");

	const char* start = header;
	const char* end = header + strlength(header) - 1;

	// 跳过开头的空格和'<'
	while (*start != '\0' && (*start == ' ' || *start == '<')) {
		start++;
	}

	// 跳过结尾的空格和'>'
	while (end >= start && (*end == ' ' || *end == '>')) {
		end--;
	}

	// 计算有效内容长度
	size_t len = (end >= start) ? (end - start + 1) : 0;

	// 分配内存：2个双引号 + 内容长度 + 结束符
	char* result = (char*)malloc((len + 3) * sizeof(char));
	if (result == NULL) return NULL;

	// 构建结果字符串
	result[0] = '"';
	if (len > 0) {
		CopyNc(start, result + 1, len);
			//strncpy(result + 1, start, len);
	}
	result[len + 1] = '"';
	result[len + 2] = '\0';

	return result;
}
int static Test005(const hyperlex::dictionary& para)
{
	int error = 0;
	const char* test_cases[] = {
		// 1. 标准格式
		"   <stdio.h>   ",
		// 2. 无空格
		"<stdlib.h>",
		// 3. 无尖括号
		"  math.h  ",
		// 4. 带空路径的分隔符
		"   <>   ",
		// 5. 空字符串
		"",
		// 6. 包含路径分隔符
		"<sys/stat.h>",
		// 7. 多个连续空格
		"<    stdio.h    >",
		// 8. 包含空格的文件名
		"<my header.h>",
		// 9. 缺少结束尖括号
		"<unistd.h",
		// 10. 缺少开始尖括号
		"ctype.h>",
		// 11. 混合空格和尖括号
		" <  complex  .h  > ",
		// 12. 特殊字符
		"<regex@library.h>",
		// 13. 只有尖括号
		"<>",
		// 14. 前后有混合符号
		"!<config.h>#"
	};
	hyperlex::Morpheme MMM;
	printf("%-25s %-25s %s\n", "input", "output", "解释");
	printf("-------------------------------------------------\n");
	for (int i = 0; i < 14; i++) {
		hyperlex::BufferChar BC;
		BC = test_cases[i];
		MMM.append(BC, 1, 1);
	}
	MMM.AppendEnd(0);
	MMM.Demo(stdout);
	for (int i = 0; i < 14; i++) {
		char* result = string_from_header(test_cases[i]);
		char* haha = MMM.GetHeader(i + 1);
		printf("|%-20s|  |%-20s| ,|%-20s|  |%s|\n",
			test_cases[i],
			result,
			haha,
			strlen(result) > 2 ? "正常" :
			strcmp(result, "\"\"") == 0 ? "空路径" : "特殊处理");
		free(result);
		free(haha);
	}

	return error;
}
#include <iostream>
#include <cassert>
#include <cstdio>
#include <string> 
#include <cstring>
#include <sstream>
namespace hyperlex
{
	std::string to_string(size_t value) {
		std::ostringstream oss;
		oss << value;
		return oss.str();
	}

	std::string to_string(int value) {
		std::ostringstream oss;
		oss << value;
		return oss.str();
	}

	std::string to_string(double value) {
		std::ostringstream oss;
		oss << value;  // 默认精度为6位小数
		return oss.str();
	}

	void test_string_pool() {
		// 测试1: 添加单个字符串
		{
			hyperlex::StringPool pool;
			const char* str1 = "hello";
			size_t id1 = pool.append(str1);
			assert(id1 == 0);
			assert(strcmp(pool.getString(id1), str1) == 0);
			assert(pool.size() == 1);
			assert(pool.count() == 1);
			assert(pool.contains(str1));
			printf("✅ Test 1 passed: Adding single string.\n");
		}

		// 测试2: 重复添加相同字符串
		{
			hyperlex::StringPool pool;
			const char* str1 = "hello";
			size_t id1 = pool.append(str1);
			size_t id2 = pool.append(str1);
			assert(id1 == id2);
			assert(pool.size() == 1);
			assert(pool.count() == 1);
			printf("✅ Test 2 passed: Adding duplicate string.\n");
		}

		// 测试3: 添加多个字符串并检查ID
		{
			hyperlex::StringPool pool;
			const char* str2 = "world";
			const char* str3 = "test";
			size_t id2 = pool.append(str2);
			size_t id3 = pool.append(str3);
			assert(id2 == 0);
			assert(id3 == 1);
			assert(pool.size() == 2);
			assert(pool.count() == 2);
			printf("✅ Test 3 passed: Adding multiple strings and checking IDs.\n");
		}

		// 测试4: 数组扩容
		{
			hyperlex::StringPool pool;
			assert(pool.arrayCapacity == 0);
			for (size_t i = 0; i < 8; ++i) {
				char buffer[10];
				sprintf(buffer, "str%d", i);
				pool.append(buffer);
			}
			assert(pool.arrayCapacity == 8);
			assert(pool.arraySize == 8);

			char buffer[10];
			sprintf(buffer, "str%d", 8);
			pool.append(buffer);
			assert(pool.arrayCapacity == 16);
			assert(pool.arraySize == 9);
			printf("✅ Test 4 passed: Array resizing.\n");
		}

		// 测试5: 哈希表扩容
		{
			hyperlex::StringPool pool;
			size_t trigger_resize = pool.bucketCount * pool.LOAD_FACTOR;
			if (static_cast<double>(trigger_resize) / pool.bucketCount > pool.LOAD_FACTOR)
				trigger_resize -= 1;
			for (size_t i = 0; i < trigger_resize; ++i) {
				char buffer[20];
				sprintf(buffer, "unique_str_%zu", i);
				pool.append(buffer);
			}
			assert(pool.count() == trigger_resize);
			assert(pool.bucketCount == 64);

			char buffer_last[20];
			sprintf(buffer_last, "trigger_resize");
			pool.append(buffer_last);
			assert(pool.bucketCount == 128);

			for (size_t i = 0; i < trigger_resize; ++i) {
				char buffer[20];
				sprintf(buffer, "unique_str_%zu", i);
				assert(pool.contains(buffer));
			}
			assert(pool.contains(buffer_last));
			printf("✅ Test 5 passed: Hash table resizing.\n");
		}

		// 测试6: contains方法
		{
			hyperlex::StringPool pool;
			const char* str1 = "hello";
			pool.append(str1);
			assert(pool.contains(str1) == true);
			assert(pool.contains("non_existent") == false);
			printf("✅ Test 6 passed: contains method.\n");
		}

		// 测试7: 越界访问
		{
			hyperlex::StringPool pool;
			const char* str1 = "hello";
			pool.append(str1);
			assert(pool.getString(0) != NULL);
			assert(pool.getString(1) == NULL);
			assert(pool.getString(9999) == NULL);
			printf("✅ Test 7 passed: Out-of-bounds access.\n");
		}

		// 测试8: NULL指针处理
		{
			hyperlex::StringPool pool;
			assert(pool.append(NULL) == (size_t)-1);
			printf("✅ Test 8 passed: NULL pointer handling.\n");
		}

		// 测试9: 哈希冲突处理
		{
			hyperlex::StringPool pool;
			const char* conflict1 = "a";
			const char* conflict2 = "A";
			size_t id1 = pool.append(conflict1);
			size_t id2 = pool.append(conflict2);
			assert(id1 != id2);
			assert(strcmp(pool.getString(id1), conflict1) == 0);
			assert(strcmp(pool.getString(id2), conflict2) == 0);
			assert(pool.contains(conflict1));
			assert(pool.contains(conflict2));
			printf("✅ Test 9 passed: Hash collision handling.\n");
		}

		// 测试10: 调试函数（手动验证）
		{
			hyperlex::StringPool pool;
			const char* str1 = "hello";
			pool.append(str1);
			// pool.demo(stdout); // 可视化输出，检查是否有警告
			printf("✅ Test 10 passed: Debug function check (manual verification needed).\n");
		}

		printf("✅ All StringPool tests passed!\n");
	}


	// 测试1: 添加新字符串返回唯一ID
	void testAppendNewString() {
		StringPool pool;
		size_t id1 = pool.append("hello");
		size_t id2 = pool.append("world");
		assert(id1 == 0); // 首个ID应为0
		assert(id2 == 1); // 后续ID递增
		std::cout << "testAppendNewString: PASSED\n";
	}

	// 测试2: 重复添加相同字符串返回相同ID
	void testAppendDuplicate() {
		StringPool pool;
		size_t id1 = pool.append("test");
		size_t id2 = pool.append("test");
		assert(id1 == id2); // ID必须一致
		std::cout << "testAppendDuplicate: PASSED\n";
	}

	// 测试3: 空指针安全处理
	void testNULLHandling() {
		StringPool pool;
		size_t id = pool.append(NULL);
		assert(id == static_cast<size_t>(-1)); // 返回错误标识
		std::cout << "testNULLHandling: PASSED\n";
	}

	// 测试4: 通过ID获取字符串
	void testGetString() {
		StringPool pool;
		const char* input = "data";
		size_t id = pool.append(input);
		const char* output = pool.getString(id);
		assert(output != NULL); // 非空指针
		assert(std::string(output) == input); // 内容一致
		assert(pool[id] != NULL); // 运算符[]功能正常
		std::cout << "testGetString: PASSED\n";
	}

	// 测试5: 非法ID访问
	void testInvalidId() {
		StringPool pool;
		assert(pool.getString(100) == NULL); // 超范围返回NULL
		assert(pool[100] == NULL); // 运算符[]同理
		std::cout << "testInvalidId: PASSED\n";
	}

	// 测试6: 字符串存在性检查
	void testContains() {
		StringPool pool;
		pool.append("exist");
		assert(pool.contains("exist") == true); // 存在时返回true
		assert(pool.contains("missing") == false); // 不存在时返回false
		std::cout << "testContains: PASSED\n";
	}

	// 测试7: 空池行为
	void testEmptyPool() {
		StringPool pool;
		assert(pool.size() == 0); // 初始大小为0
		assert(pool.getString(0) == NULL); // 空池访问返回NULL
		assert(pool.contains("any") == false); // 空池不包含任何字符串
		std::cout << "testEmptyPool: PASSED\n";
	}

	// 测试8: 内部数据结构一致性
	void testInternalConsistency() {
		StringPool pool;
		pool.append("A");
		pool.append("B");
		assert(pool.size() == pool.count()); // vector与map大小必须相等
		pool.demo(); // 自检函数无警告输出（观察控制台）
		std::cout << "testInternalConsistency: PASSED\n";
	}

	// 测试9: 大量插入压力测试1
	void testMassInsertion() {
		StringPool pool;
		const size_t COUNT = 1000;
		const size_t FACTOR = 100;
		for (size_t j = 0; j < COUNT * FACTOR; ++j) {
			size_t i = j % COUNT;
			std::string s = "str_" + to_string(i);
			size_t id = pool.append(s.c_str());
			assert(id == i); // ID连续分配
		}
		std::cout << "COUNT: " << COUNT << std::endl;
		std::cout << "pool.size(): " << pool.size() << std::endl;
		std::cout << "pool.count(): " << pool.count() << std::endl;
		std::cout << "pool.countCollisions(): " << pool.countCollisions() << std::endl;
		assert(pool.size() == COUNT); // 总数正确
		assert(pool.count() == COUNT); // map大小同步
		std::cout << "testMassInsertion: PASSED\n";
	}
	// 测试10: 大量插入压力测试2
	void testMassInsertion2()
	{
		StringPool pool;
		const size_t COUNT = 1000;
		const size_t FACTOR = 100;
		for (size_t j = 0; j < COUNT * FACTOR; ++j) {
			size_t i = j / FACTOR;
			std::string s = "str_" + to_string(i);
			size_t id = pool.append(s.c_str());
			assert(id == i); // ID连续分配
		}
		std::cout << "COUNT: " << COUNT << std::endl;
		std::cout << "pool.size(): " << pool.size() << std::endl;
		std::cout << "pool.count(): " << pool.count() << std::endl;
		std::cout << "pool.countCollisions(): " << pool.countCollisions() << std::endl;
		assert(pool.size() == COUNT); // 总数正确
		assert(pool.count() == COUNT); // map大小同步
		std::cout << "testMassInsertion2: PASSED\n";
	}
	// 测试11: 超长字符串处理
	void testLongString() {
		StringPool pool;
		char longStr[1000];
		for (size_t i = 0; i < 999; ++i) {
			longStr[i] = 'a';
		}
		longStr[999] = '\0';
		size_t id = pool.append(longStr);
		const size_t FACTOR = 100;
		for (size_t j = 0; j < FACTOR; ++j) {
			size_t i = j;
			std::string s = longStr;
			size_t id2 = pool.append(s.c_str());
			assert(id2 == id); // ID连续分配
		}
		assert(id == 0);
		assert(strcmp(pool.getString(id), longStr) == 0);
		assert(pool.contains(longStr));
		std::cout << "testLongString: PASSED\n";
	}
	// 测试12: 大量插入压力测试3
	void testMassInsertion3()
	{
		StringPool pool;
		const size_t COUNT = 1024 * 1024 * 64; // 64M
		const size_t FACTOR = 2;
		for (size_t j = 0; j < COUNT * FACTOR; ++j) {
			size_t i = j % COUNT;
			std::string s = "str_" + to_string(i);
			size_t id = pool.append(s.c_str());
			assert(id == i); // ID连续分配
		}
		std::cout << "COUNT: " << COUNT << std::endl;
		std::cout << "pool.size(): " << pool.size() << std::endl;
		std::cout << "pool.count(): " << pool.count() << std::endl;
		std::cout << "pool.countCollisions(): " << pool.countCollisions() << std::endl;
		assert(pool.size() == COUNT); // 总数正确
		assert(pool.count() == COUNT); // map大小同步
		std::cout << "testMassInsertion3: PASSED\n";
	}

	// 测试13:  测试 clear 方法
	void testClear()
	{
		hyperlex::StringPool pool;
		pool.append("A");
		pool.append("B");
		assert(pool.size() == 2);

		pool.clear();
		assert(pool.size() == 0);        // 验证清空后大小为0
		assert(pool.count() == 0);       // 哈希表节点数应为0
		assert(!pool.contains("A"));    // 内容应不存在
		assert(pool.getString(0) == NULL); // ID访问返回空

		// 清空后重新添加
		size_t newId = pool.append("C");
		assert(newId == 0);  // ID应从0开始重新分配
		printf("✅ testClear PASSED\n");
	}

	//  测试14: 测试 copy 方法（深拷贝）
	void testCopy() {
		hyperlex::StringPool src;
		src.append("X");
		src.append("Y");

		// 深拷贝测试
		hyperlex::StringPool dest;
		dest.copy(src);
		assert(dest.size() == 2);
		assert(dest.getString(0) != src.getString(0)); // 指针地址不同
		assert(strcmp(dest[0], "X") == 0);              // 内容一致

		// 自赋值安全测试
		dest.copy(dest);
		assert(dest.size() == 2);  // 数据不应丢失
		printf("✅ testCopy PASSED\n");
	}

	//  测试15: 测试 append 方法（合并池）
	void testAppendPool() {
		hyperlex::StringPool dest;
		dest.append("A");

		hyperlex::StringPool src;
		src.append("B");
		src.append("C");

		vector<size_t> newIds;
		dest.append(src, newIds); // 合并源池

		// 验证映射关系
		assert(newIds.count() == 2);
		assert(newIds[0] == 1);   // "B" 在目标池的新ID
		assert(newIds[1] == 2);   // "C" 在目标池的新ID
		assert(dest.size() == 3); // 总数=1(A)+2(B/C)

		// 重复合并测试
		dest.append(src, newIds);
		assert(newIds[0] == 1);   // 重复字符串应返回现有ID
		assert(dest.size() == 3); // 总数不变（去重）
		printf("✅ testAppendPool PASSED\n");
	}


	// 测试16: 测试空池操作边界
	void testEmptyOperations()
	{
		hyperlex::StringPool empty;

		// 清空空池
		empty.clear();
		assert(empty.size() == 0);

		// 合并空池到目标池
		hyperlex::StringPool dest;
		vector<size_t> newIds;
		dest.append(empty, newIds);
		assert(newIds.count() == 0); // 映射列表应为空

		// 拷贝空池
		hyperlex::StringPool dest2;
		dest2.copy(empty);
		assert(dest2.size() == 0);
		printf("✅ testEmptyOperations PASSED\n");
	}

	//  测试17: 测试 append 方法（合并池）
	void testAppendPool2() {
		StringPool pool;
		const size_t COUNT = 1000;
		const size_t FACTOR = 100;
		for (size_t j = 0; j < COUNT * FACTOR; ++j) {
			size_t i = j / FACTOR;
			std::string s = "str_" + to_string(i);
			size_t id = pool.append(s.c_str());
			assert(id == i); // ID连续分配
		}
		std::cout << "COUNT: " << COUNT << std::endl;
		std::cout << "pool.size(): " << pool.size() << std::endl;
		std::cout << "pool.count(): " << pool.count() << std::endl;
		std::cout << "pool.countCollisions(): " << pool.countCollisions() << std::endl;
		assert(pool.size() == COUNT); // 总数正确
		assert(pool.count() == COUNT); // map大小同步


		StringPool dst;
		dst.copy(pool);
		assert(dst.size() == pool.size()); // 确保大小一致

		vector<size_t> NewId;
		dst.append(pool, NewId);
		for (size_t i = 0; i < COUNT; i++)
		{
			assert(pool.count() == COUNT);
		}
		assert(dst.size() == pool.size()); // 确保大小一致
		std::cout << "testAppendPool2: PASSED\n";
	}

	int test2222() {
		testAppendNewString();
		testAppendDuplicate();
		testNULLHandling();
		testGetString();
		testInvalidId();
		testContains();
		testEmptyPool();
		testClear();
		testCopy();
		testAppendPool();
		testEmptyOperations();
		testAppendPool2();

		testInternalConsistency();
		testMassInsertion();
		testMassInsertion2();
		testLongString();
		testMassInsertion3();

		std::cout << "\nALL TESTS PASSED!\n";


		return 0;
	}

}
int static Test006(const hyperlex::dictionary& para)
{
	int error = 0;
	hyperlex::test2222();
	hyperlex::test_string_pool();
	{
		hyperlex::StringPool Pool;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "j: " << Pool.append("j") << std::endl;
		std::cout << "k: " << Pool.append("k") << std::endl;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "k: " << Pool.append("k") << std::endl;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "k: " << Pool.append("k") << std::endl;
		std::cout << "i: " << Pool.append("i") << std::endl;
		std::cout << "ii: " << Pool.append("ii") << std::endl;
		std::cout << "kk: " << Pool.append("kk") << std::endl;
		std::cout << "jj: " << Pool.append("jj") << std::endl;
		Pool.demo();
	}
	return error;
}
int static Test007(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test008(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test009(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test010(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test011(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test012(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test013(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test014(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test015(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test016(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test017(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test018(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test019(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test020(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test021(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test022(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test023(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test024(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test025(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test026(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test027(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test028(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test029(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test030(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test031(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test032(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test033(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test034(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test035(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test036(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test037(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test038(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test039(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test040(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test041(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test042(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test043(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test044(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test045(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test046(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test047(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test048(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test049(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test050(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test051(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test052(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test053(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test054(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test055(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test056(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test057(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test058(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test059(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test060(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test061(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test062(const hyperlex::dictionary& para)
{
	int error = 0;
	return error;
}
int static Test063(const hyperlex::dictionary& para)
{
	int error = 0;
	for (size_t i = 0; i < 64; i++)
	{
		printf("int static Test");
		if (i < 10) printf("00%zu", i);
		else if (i < 100) printf("0%zu", i);
		else printf("%zu", i);
		printf("(const hyperlex::dictionary& para)");
		if (error == 0)
		{
			printf("\n{\n");
			printf("\tint error = 0;\n");
			printf("\treturn error;\n");
			printf("}\n");
		}
		else
		{
			printf(";");
		}
	}

	for (size_t i = 2; i < 64; i++)
	{
		printf("\t\tcase ");
		printf("%zu:\n\t\t{\n\t\t\terror = Test", i);
		if (i < 10) printf("00%zu", i);
		else if (i < 100) printf("0%zu", i);
		else printf("%zu", i);
		printf("(para);\n");
		printf("\t\t\tbreak;\n");
		printf("\t\t}\n");
	}
	return error;
}




static char* CopyMalloc(const char* s)
{
	char* v;
	size_t size;
	size = strlength(s);
	v = (char*)malloc(sizeof(char) * (size + 4));
	for (size_t i = 0; i < size; i++) v[i] = s[i];
	v[size] = '\0';
	return v;
}
static void CopyNc(const char* src, char* dst, size_t length)
{
	for (size_t i = 0; i < length; i++) dst[i] = src[i];
}
static bool compare(const char* str1, const char* str2)
{
	size_t i;
	for (i = 0; (str1[i] != '\0') && (str1[i] == str2[i]); i++);
	return str1[i] == str2[i];
}
static void write_escaped_string(const char* str, FILE* file)
{
	if (!str || !file) return;

	fputc('\"', file);  // 字符常量起始引号

	for (int i = 0; str[i] != '\0'; i++) {
		switch (str[i]) {
			// 处理必须转义的特殊字符
		case '\"': fputs("\\\"", file); break;   // 双引号[6,8](@ref)
		case '\\': fputs("\\\\", file); break;   // 反斜杠[6,7](@ref)
		case '\n': fputs("\\n", file); break;    // 换行符[1,6](@ref)
		case '\t': fputs("\\t", file); break;    // 制表符[1,8](@ref)
		case '\v': fputs("\\v", file); break;    // 制表符[1,8](@ref)
		case '\r': fputs("\\r", file); break;    // 回车符[6,8](@ref)
		case '\b': fputs("\\b", file); break;    // 退格符[7,8](@ref)
		case '\f': fputs("\\f", file); break;    // 换页符[8](@ref)
		case '\a': fputs("\\a", file); break;    // 响铃符[8](@ref)
			// 其他不可打印字符用十六进制转义
		default:
			if (str[i] < 32 || str[i] > 126) {  // 非ASCII可打印字符
				fprintf(file, "\\x%02X", (unsigned char)str[i]);  // 十六进制转义[6](@ref)
			}
			else {
				fputc(str[i], file);  // 直接写入可打印字符
			}
		}
	}
	fputc('\"', file);  // 字符常量结束引号
}
static size_t strlength(const char* str)
{
	size_t i;
	for (i = 0; str[i] != '\0'; i++);
	return i;
}



